require "src/tools/object"

SpriteFrameMgr = object:new()
function SpriteFrameMgr:getInstance()
  if self.instance == nil then
    self.instance = self:new()
  end
  return self.instance
end
function SpriteFrameMgr:addSpriteFrameFile(plist)
  cc.SpriteFrameCache:getInstance():addSpriteFrames(plist)
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon0.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon1.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon2.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon3.plist")
end

function SpriteFrameMgr:cleanupPurgeCachedResource()
  cc.AnimationCache:destroyInstance()
  cc.Director:getInstance():purgeCachedData()
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon0.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon1.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon2.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon3.plist")
end

function SpriteFrameMgr:cleanupResource()
  cc.Director:getInstance():getTextureCache():removeUnusedTextures()
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon0.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon1.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon2.plist")
  cc.SpriteFrameCache:getInstance():addSpriteFrames("ui/Json/LayerCommon/LayerCommon3.plist")
end

function SpriteFrameMgr:getExtraResList()
  return SpriteFrameMgr:getInstance().m_resList
end
